// create the context menu
    var menu = contextmenu([                 
      {
    	  label: "Design Studio Datasource",
    	  onclick : function(e){
    		  addData({
	    			  id : "...",
	    			  type : 'designstudio'
    		  });
    	  }
      },
      {
    	 label : 'String (JSON)',
    	   		onclick : function(e){
    	   			addData({
  	    			  id : "...",
  	    			  type : 'String',
  	    			  format : 'JSON',
  	    			  data : [{"col1" : "...", "col2" : "...", "col3" : "..."},{"col1" : "...", "col2" : "...", "col3" : "..."}]
  	    		   });
    	   }
      },
      {
    	  hr: true
      },
      { 
    	  label: "Sample Data",
    	  children: [
    	      {
        	      label: "Two JSON objects",
        	      onclick : function(e){
        		     editor_config.getSession().setValue('[\n    {\n        "id" : "model1",\n        "type" : "JSON",\n        "data" : [\n            { "colName1" : "New York", "colName2" : "WA" },\n            { "colName1" : "Las Vegas", "colName2" : "NV" },\n            { "colName1" : "Boston", "colName2" : "MA" },\n            { "colName1" : "Portland", "colName2" : "OR" }\n        ]\n    },\n\n    {\n        "id" : "model2",\n        "type" : "JSON",\n        "data" : [\n            { "colName1" : "A", "colName2" : 10 },\n            { "colName1" : "B", "colName2" : 20 },\n            { "colName1" : "C", "colName2" : 30 },\n            { "colName1" : "D", "colName2" : 40 }\n        ]\n    }\n]');
        	      }
        	 }
         ]
      }
    ]);
    contextmenu.attach($("#editor_config"), menu);
    
    
    // function to add a resource to the editor
    function addData( config ){
    	
    	
    	// check mandatory parameters
    	if(config.id === undefined || config.id === null || config.id === "" || config.type === undefined || config.type === null || config.type === ""){
    		return;
    	}
    	
    	// if the editor is empty, add the array brackets
    	var isEmpty = false;
    	if(editor_config.getSession().getValue() === ""){
    		isEmpty = true;
    	}
    	
    	// build up string
    	var newString = "";
    	
    	// add the opening brackets if required
    	if(isEmpty){
    		newString += '[\n    ';
    	}
    	
    	// id and type are mandatory
    	newString += '{\n        "id" : "' + config.id + '",\n        "type" : "' + config.type + '"';
    	
    	// add all the remaining information
    	for (var property in config) {
    		  if (config.hasOwnProperty(property)) {
    			  
    			  // skip properties that are already added
    			  if(property === 'id' || property === 'type' || property === 'data')
    				  continue;
    			  
    			  newString += ',\n        "' + property + '" : "' + config[property] + '"';
    		  }
    	}
    	
    	// data can be provided as object string
    	if(config.data !== undefined && config.data !== null){
    		newString += ',\n        "data" : [';
    		
    		// loop over the records in the data array
    		for(var i=0;i<config.data.length;i++){
    			if(i>0){
    				newString += ',';
    			}
    			
    			newString += '\n            {';
    			
    			// check all properties
    			var firstProperty = true;
    			for (var property in config.data[i]) {
    				  if(!firstProperty){
    					newString += ',';
    				  }
		    		  if (config.data[i].hasOwnProperty(property)) {
		    			  newString += '\n                "' + property + '" : "' + config.data[i][property] + '"';
		    		  }
		    		  firstProperty = false;
    	    	}
    			
    			newString += '\n            }';
    		}
    		
    		
    		newString += '\n        ]';
    	}
    	
    	// close the data
    	newString += '\n    }';
    	
    	// add the closing brackets if required
    	if(isEmpty){
    		newString += '\n]';
    	}
    	
    	// add the new resource after the last defined resource (if available)
    	editor_config.moveCursorToPosition({row : 99999, column : 1});
    	if(editor_config.find("}", { backwards : true} ) !== undefined){
    		editor_config.insert("},\n\n    " + newString);
    	}else{
    		// add it to the editor
        	editor_config.insert(newString);
    	}
    	
    }